package com.tony.demo.ui.performance.xnyh.draw;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.tony.demo.R;
import com.tony.demo.mvp.presenter.impl.BasePresenter;
import com.tony.demo.ui.base.BaseActivity;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

public class DrawAndLayoutActivity extends BaseActivity implements AdapterView.OnItemClickListener {

    private List<String> list = new ArrayList<>();

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int getViewLayout() {
        return R.layout.activity_test;
    }

    protected void initData() {
        ListView listView = findViewById(R.id.list_view);

        list.add("布局过度绘制");
        list.add("布局过度绘制优化后");
        list.add("自定义控件过度绘制");
        listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, list));

        listView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        onItemClick((String) parent.getAdapter().getItem(position));
    }

    private void onItemClick(String item) {
        switch (item) {
            case "布局过度绘制": {
                EventBus.getDefault().postSticky("false");
                startActivity(ChatumLatinumActivity.class);
                break;
            }
            case "布局过度绘制优化后": {
                EventBus.getDefault().postSticky("true");
                startActivity(ChatumLatinumActivity.class);
                break;
            }
            case "自定义控件过度绘制": {
                startActivity(DroidCardsActivity.class);
                break;
            }
        }
    }
}
